import http from '../../tool/http'


const state={
    //存放所有菜品分类数据
    ClassifyName:{

    } ,
    CountA:1,
    CountB:1,
    getCurrentDataA:[],
    searchCurrentDataA:[],
    getCurrentDataB:[],
    searchCurrentDataB:[]
}
const actions={
    getDishesMainCount({commit}){
        return http({
            url:'/mgrsite/dishesMainController/getDishesMainCount',
            method:'post',
        }).then(res=>{
            // console.log(res.data.count)
            commit('addCountA',res.data.count)
        })
    },
    getClassifyCount({commit}){
        return http({
            url:'/mgrsite/dishesClassifyController/getDishesClassifyCount',
            method:'post',
        }).then(res=>{
            // console.log(res.data.count)
            commit('addCountB',res.data.count)
        })
    },
    getClassifyName({commit}){
          return http({
              url:'/mgrsite/dishesClassifyController/getClassifyName',
              method:'post',
          }).then(res=>{
              commit('addClassifyName',res.data)
          })
    } ,
    getCurrentDataA({commit},data){
        let num1=data[0]
        let num2=data[1]
        // console.log(data)
        return http({
            url:'/mgrsite/dishesMainController/getDishesMain',
            method:'post',
            data:{num1:num1,num2:num2}
        }).then(res=>{
            // console.log(res.data.Data)
            commit('addGetDataA',res.data.Data)
            return 200
        })
    } ,
    searchCurrentDataA(context,data){
        console.log(data)
        let name=data.name
        let classify_name=data.classify_name
        // let pageNum=data.pageNum
        return http({
            url:'/mgrsite/dishesMainController/searchDishesMain',
            method:'post',
            data:{name:name,classify_name: classify_name}
        }).then(res=>{
            console.log(res)
            
            context.commit('addSrarchDataA',res.data.Data)
            return 200
        })
    },
    getCurrentDataB({commit},data){
        let num1=data[0]
        let num2=data[1]
        return http({
            url:'/mgrsite/dishesClassifyController/getDishesClassify',
            method:'post',
            data:{num1:num1,num2:num2}
        }).then(res=>{
            // console.log(res)
            commit('addGetDataB',res.data.Data)
            return 200
        })
    } ,
    searchCurrentDataB(context,data){
        // console.log(data)
        let name=data.name
        return http({
            url:'/mgrsite/dishesClassifyController/searchDishesClassify',
            method:'post',
            data:{name:name}
        }).then(res=>{
            console.log(res)
            context.commit('addSrarchDataB',res.data.Data)
            return 200
        })
    }
}
const mutations={
    addCountA(state,data){
        state.CountA=data
        // console.log(state.Count)

    },
    addCountB(state,data){
        state.CountB=data
        // console.log(state.Count)

    },
    addGetDataA(state,data){
        state.getCurrentDataA=data
    } ,
    addSrarchDataA(state,data){
        state.searchCurrentDataA=data
        // console.log(state.searchCurrentDataA)
    },
    addGetDataB(state,data){
        state.getCurrentDataB=data
        // console.log(state.getCurrentData)
    } ,
    addSrarchDataB(state,data){
        state.searchCurrentDataB=data
    },
    addClassifyName(state,data){
        state.ClassifyName=data
    }
}
const getters={

}


export default {
    state,
    actions ,
    mutations,
    getters
}


